//
//  DetailWeatherViewController.m
//  Funny
//
//  Created by dllo on 15/11/2.
//  Copyright © 2015年 King. All rights reserved.
//

#import "DetailWeatherViewController.h"
#import "DetailWheatherModel.h"
@interface DetailWeatherViewController ()
@property (nonatomic, strong) UIImageView *bgImageView;
@property (nonatomic, strong) UILabel *titleLable;
@property (nonatomic, strong) UILabel *pmLable;
@property (nonatomic, strong) DetailWheatherModel *weatherModel;
@property (nonatomic, strong) UILabel *numberLable;
@property (nonatomic, strong) UIImageView *hostImageView;
@property (nonatomic, strong) UILabel *timeLable;
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *wenLable;
@property (nonatomic, strong) UILabel *stateLable;
@property (nonatomic, strong) UIImageView *remindImageView;
@property (nonatomic, strong) UILabel *remindLable;
@end

@implementation DetailWeatherViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =[UIColor orangeColor];
    [self handleData];
    [self creatView];
    
}

- (void)creatView
{
    self.bgImageView = [[UIImageView alloc]initWithFrame:CGRectMake(60 * W, 15 * H, 250 * W, 250 * H)];
    self.bgImageView.backgroundColor = [UIColor colorWithRed:230/255.0 green:80/255.0 blue:10/255.0 alpha:0.3];
    self.bgImageView.layer.masksToBounds = YES;
    self.bgImageView.layer.cornerRadius = 125 * W;
    [self.view addSubview:_bgImageView];
    
    self.titleLable = [[UILabel alloc]initWithFrame:CGRectMake(30 * W, 30 * H, 190 * W, 30 * H)];
    self.titleLable.font = [UIFont systemFontOfSize:13];
    self.titleLable.textColor = [UIColor whiteColor];
    self.titleLable.textAlignment = NSTextAlignmentCenter;
    self.titleLable.text = @"空气质量";
    [self.bgImageView addSubview:_titleLable];
    
    self.pmLable = [[UILabel alloc]initWithFrame:CGRectMake(30 * W, 190 * H, 190 * W, 30 * W)];
    self.pmLable.font = [UIFont systemFontOfSize:20];
    self.pmLable.textColor = [UIColor whiteColor];
    self.pmLable.textAlignment = NSTextAlignmentCenter;
    self.pmLable.text = @"PM2.5";
    [self.bgImageView addSubview:_pmLable];
    
    self.numberLable = [[UILabel alloc]initWithFrame:CGRectMake(30 * W, 70 * H, 190 * W, 110 * H)];
    self.numberLable.font = [UIFont systemFontOfSize:80];
    self.numberLable.textColor = [UIColor whiteColor];
    self.numberLable.textAlignment = NSTextAlignmentCenter;
    [self.bgImageView addSubview:_numberLable];
}

#pragma mark -处理数据
- (void)handleData
{
    NSString *str = [NSString stringWithFormat:@"http://appapi.yaochufa.com/v2/Product/GetWeatherInfoByCity?productId=%@&machineCode=00000000-58ca-002b-e3ba-8a9569d38c36&version=4.4.0&system=android&channel=nearme", self.productId];
    [HandleData handleDataWithUrl:str completion:^(id data) {
        self.weatherModel = [DetailWheatherModel modelWithDic:[[[data objectForKey:@"data"] objectForKey:@"results"] firstObject]];
        self.numberLable.text = self.weatherModel.pm25;
        
        
        for (int i = 0; i < 4; i++) {
            CGFloat x = self.view.bounds.size.width/4 *i;
            CGFloat y = 425 * H;
            self.hostImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, self.view.bounds.size.width/4-1, 130 * H)];
            _hostImageView.backgroundColor = [UIColor colorWithRed:120/255.0 green:90/255.0 blue:20/255.0 alpha:0.3];
            [self.view addSubview:_hostImageView];
            
            self.timeLable = [[UILabel alloc]initWithFrame:CGRectMake(30 * W, 5 * H, 25 * W, 20 * H)];
            self.timeLable.backgroundColor = [UIColor clearColor];
            self.timeLable.textColor = [UIColor colorWithRed:250/255.0 green:180/255.0 blue:70/255.0 alpha:1.0];
            self.timeLable.textAlignment = NSTextAlignmentLeft;
            self.timeLable.lineBreakMode = NO;
            self.timeLable.text = [[self.weatherModel.weather_Data objectAtIndex:i]objectForKey:@"date"];
            self.timeLable.font = [UIFont systemFontOfSize:12];
            [self.hostImageView addSubview:_timeLable];
            
            self.iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(20 * W, 30 * H, 50 * W, 50 * H)];
            self.iconImageView.backgroundColor =[UIColor clearColor];
            self.iconImageView.layer.masksToBounds = YES;
            self.iconImageView.layer.cornerRadius = 25;
            [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:[[self.weatherModel.weather_Data objectAtIndex:i]objectForKey:@"dayPictureUrl"]]];
            [self.hostImageView addSubview:_iconImageView];
            
            self.wenLable = [[UILabel alloc]initWithFrame:CGRectMake(5 * W, 85 * H, 85 * W, 25 * H)];
            self.wenLable.backgroundColor = [UIColor clearColor];
            self.wenLable.textColor = [UIColor whiteColor];
            self.wenLable.text = [[self.weatherModel.weather_Data objectAtIndex:i]objectForKey:@"temperature"];
            self.wenLable.textAlignment = NSTextAlignmentCenter;
            [self.hostImageView addSubview:_wenLable];
            
            self.stateLable = [[UILabel alloc]initWithFrame:CGRectMake(15 * W, 110 * H, 60 * W, 16 * H)];
            self.stateLable.backgroundColor = [UIColor clearColor];
            self.stateLable.text = [[self.weatherModel.weather_Data objectAtIndex:i]objectForKey:@"weather"];
            self.stateLable.textColor = [UIColor whiteColor];
            self.stateLable.textAlignment = NSTextAlignmentCenter;
            self.stateLable.font = [UIFont systemFontOfSize:12];
            [self.hostImageView addSubview:_stateLable];
            
            
            CGFloat x1 = 10 * W;
            CGFloat y1 = (300+i*30) * H;
            self.remindImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x1, y1, 24 * W, 24 * H)];
            self.remindImageView.backgroundColor = [UIColor yellowColor];
            self.remindImageView.layer.masksToBounds = YES;
            self.remindImageView.layer.cornerRadius = 12;
            [self.remindImageView setImage:[UIImage imageNamed:@"icon3.png"]];
            [self.view addSubview:self.remindImageView];
            
            self.remindLable = [[UILabel alloc]initWithFrame:CGRectMake(40 * W, y1, self.view.bounds.size.width-50 * W, 24 * H)];
            self.remindLable.font = [UIFont systemFontOfSize:12];
            self.remindLable.lineBreakMode = NO;
            self.remindLable.textColor = [UIColor whiteColor];
            self.remindLable.backgroundColor = [UIColor clearColor];
            self.remindLable.text = [[self.weatherModel.index objectAtIndex:i]objectForKey:@"des"];
            [self.view addSubview:_remindLable];
            
        }
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
